package com.csglxt.service.impl;

import java.math.BigDecimal;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.csglxt.base.DaoSupportImpl;
import com.csglxt.domain.Order;
import com.csglxt.service.OrderService;
import com.csglxt.utils.DateUtil;

/**
 * 
 * @ClassName: OrderServiceImpl
 * @Description: TODO(订单管理 业务层 实现类)
 * @author Itchbeilef
 * @date 2015-5-28 下午10:14:06
 * 
 */

@Service
@Transactional
public class OrderServiceImpl extends DaoSupportImpl<Order> implements
        OrderService {

    /**
     * 查询指定年月进货花钱总数
     */
    public BigDecimal queryByYearAndMonth(int year, int month) {

        return (BigDecimal) getSession()
                .createQuery(
                        "select sum(g.price*oi.number) FROM Order o ,OrderItem oi,Goods g WHERE o = oi.order and oi.goods = g and o.dealType =3  and o.date > ? and o.date < ?")
                //
                .setParameter(0, DateUtil.toDate(year + "-" + month, "yyyy-MM"))//
                .setParameter(1,
                        DateUtil.toDate(year + "-" + (month + 1), "yyyy-MM"))//
                .uniqueResult();

    }

}
